from demo import app
from utils.db import DB
from flask import g, session, request

def load_db():
    dbConfig = app.config['APP_DB']
    g.db = DB(dbConfig['host'], dbConfig['port'], dbConfig['user'], dbConfig['passwd'], dbConfig['name'])
    return g.db

def clear_db():
    g.db.clear()


def admin_req_log():
    user = session.get('user')
    if user:
        info = {}
        info['user'] = [user['id'], user['name'], user['role_id']]
        info['args'] = request.values
        app.logger.info(JSON.encode(info))
